#pragma once
#include<iostream>
#include<unordered_set>
#include<string>
using namespace std;

#define UOMSSIZE 100000

#include<cstdlib>
#include<stdio.h>
#include<ctime>

void tTest_UnOrderedMultiSet() {
	unordered_multiset<string> uoms;
	char buf[10];

	clock_t timeStart = clock();
	cout << "开始时间: " << timeStart << endl;
	for (int i = 0; i < UOMSSIZE; i ++) {
		try {
			snprintf(buf, 10, "%d", rand());
			uoms.insert(buf);
		}
		catch (exception& p) {
			cout << "i= " << i << " " << p.what() << endl;
			abort();
		}
	}

	cout << "unordered_multiset 赋值所需要时间: " << clock() - timeStart << endl;
	cout << "unordered_multiset 大小: " << uoms.size() << endl;
	cout << "unordered_multiset 最大大小: " << uoms.max_size() << endl;

	//当元素个数大于bucket时, bucket会增加, 变成原先的两倍, 并且将所有元素重新打散放入bucket中
	cout << "unordered_multiset bucket总数量: " << uoms.bucket_count() << endl;

	cout << "unordered_multiset bucket载重因素(因子): " << uoms.load_factor() << endl;
	cout << "unordered_multiset bucket最大载重因素(因子): " << uoms.max_load_factor() << endl;

	//获取前二十个bucket中包含的元素个数
	for (int i = 0; i < 20; i ++) {
		cout << "bucket: " << i << " 中, 有 " << uoms.bucket_size(i) << " 个元素" << endl;
	}

	string target;
	cin >> target;

	//查找, 先使用标准库
	timeStart = clock();
	unordered_multiset<string>::iterator pItem = ::find(uoms.begin(), uoms.end(), target);
	cout << "unordered_multiset 标准库find所需要时间: " << clock() - timeStart << endl;
	if(pItem != uoms.end())
		cout << "找到元素: " << *pItem << endl;
	else
		cout << "找不到" << endl;

	//查找, 使用unordered_multiset自带find
	timeStart = clock();
	pItem = uoms.find(target);
	cout << "unordered_multiset 标准库find所需要时间: " << clock() - timeStart << endl;
	if (pItem != uoms.end())
		cout << "找到元素: " << *pItem << endl;
	else
		cout << "找不到" << endl;
}